{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "acf7a630",
   "metadata": {},
   "source": [
    "### 集合不允许有重复\n",
    "#### 元音集合："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7da382f0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'a', 'e', 'i', 'o', 'u'}"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vowels = {'a','e','e','i','o','u','u'}\n",
    "vowels"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bab73343",
   "metadata": {},
   "source": [
    "#### 从序列创建集合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "80566ee9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'a', 'e', 'i', 'o', 'u'}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "vowels2 = set('aeeiouu')\n",
    "vowels2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f39df32b",
   "metadata": {},
   "source": [
    "### 充分利用集合方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "df51f5d0",
   "metadata": {},
   "outputs": [],
   "source": [
    "vowels = set('aeiou')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6aff712d",
   "metadata": {},
   "outputs": [],
   "source": [
    "word = 'hello'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "4f934ae2",
   "metadata": {},
   "outputs": [],
   "source": [
    "u = vowels.union(set(word))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f7b439c1",
   "metadata": {},
   "source": [
    "### union合并集合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e6d5c3e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "u_list = sorted(list(u))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a26c660c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a', 'e', 'h', 'i', 'l', 'o', 'u']"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "u_list"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3655c2c6",
   "metadata": {},
   "source": [
    "### difference告诉你哪些不是共有元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "b9fd638a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'a', 'i', 'u'}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "d = vowels.difference(set(word))\n",
    "d"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a57a755",
   "metadata": {},
   "source": [
    "### intersection 报告共同对象"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "6821f7e2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'e', 'o'}"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "i = vowels.intersection(set(word))\n",
    "i"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d2e34104",
   "metadata": {},
   "outputs": [],
   "source": [
    "vowels = set('aeiou')\n",
    "word = input(\"Provide a word to search for vowels: \")\n",
    "found = vowels.intersection(set(word))\n",
    "for vowel in found:\n",
    "    print(vowel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b83e15d1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "00546e0e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
